/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.mapper;

import java.util.List;
import java.util.Map;

import com.koron.purpose.bean.ResponsibilitiesLibBean;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.koron.purpose.bean.JobsStaffBean;
import com.koron.purpose.domain.JobsStaff;

public interface JobsStaffMapper {
	
	@Insert("insert into jobs_staff(id,add_user,add_time,update_user,update_time,add_user_name,update_user_name,dept_code,staff_code,staff_name,jobs_id,jobs_name,code,note)"
			+ "values(#{id},#{addUser},#{addTime},#{updateUser},#{updateTime},#{addUserName},#{updateUserName},#{deptCode},#{staffCode},#{staffName},#{jobsId},#{jobsName},#{code},#{note})")
	int insert(JobsStaff bean);
	
	@Update("update jobs_staff set update_user=#{updateUser},update_time=#{updateTime},update_user_name=#{updateUserName},"
			+ "dept_code=#{deptCode},jobs_id=#{jobsId},jobs_name=#{jobsName},note=#{note} where id=#{id}")
	int update(JobsStaff bean);
	
	@Delete("delete from jobs_staff where id=#{id}")
	int delete(@Param("id") String id);
	
	@Select("select * from jobs_staff where id=#{id}")
	JobsStaffBean queryById(@Param("id") String id);
	
	@Select("<script>"
			+ "select * from jobs_staff where staff_code in  "
			+ "<foreach collection='codeList' item='code' separator=',' open='(' close=')'> #{code} </foreach>"
			+ "</script>")
	List<JobsStaffBean> queryByCodeList(@Param("codeList") List<String> codeList);

	@Select("<script>"
			+ "select * from jobs_staff"
			+ "</script>")
	List<JobsStaff> queryAll();
	
	@Select("select count(*) from jobs_staff where staff_code=#{staffCode}")
	Integer addVerification(@Param("staffCode") String staffCode);

	@Insert("<script>" +
			"insert into jobs_staff_responsibilitie(jobs_staff_id, responsibilities_lib_id) VALUES" +
			"<foreach collection='rls' item='bean' separator =','>" +
			"(#{bean.jobsStaffId}, #{bean.responsibilitiesLibId})" +
			"</foreach>"
			+ "</script>")
	Integer batchInsertRL(@Param("rls") List<Map> rls);

	@Delete("delete from jobs_staff_responsibilitie where jobs_staff_id = #{jobsStaffId}")
	Integer deleteRLByStaffId(String jobsStaffId);

	@Select("select b.* from jobs_staff_responsibilitie a,responsibilities_lib b " +
			"WHERE a.responsibilities_lib_id = b.id and a.jobs_staff_id = #{jobsStaffId} AND b.`status` = '1'")
	List<ResponsibilitiesLibBean> getResponsibilitiesLibs(String jobsStaffId);
}
